package cn.tb.ymcc.web.controller;

import cn.tb.ymcc.dto.RegisterDto;
import cn.tb.ymcc.result.JSONResult;
import cn.tb.ymcc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 图片验证码
     * @param key
     * @return
     */
    @GetMapping("/verifycode/imageCode/{imageCodeKey}")
    public JSONResult getImgCode(@PathVariable("imageCodeKey") String key){

        String base64Str = verifyCodeService.imgCode(key);
        return JSONResult.success(base64Str);
    }

    /**
     * 短信验证码
     * @param dto
     * @return
     */
    @PostMapping("/verifycode/sendSmsCode")
    public JSONResult getSmsCode(@RequestBody @Valid RegisterDto dto){
        verifyCodeService.smsCode(dto);
        return JSONResult.success();
    }
}
